const GAME_OBJECTS=[]

export class GameObjects{
    constructor(){
        GAME_OBJECTS.push(this);
        this.delta_time=0;
        this.has_called_start=false;
    }

    start(){


    }
    update(){

    }
    on_destroy(){

    }
    destroy(){
        this.on_destroy();
        for(let i in GAME_OBJECTS){
            const obj=GAME_OBJECTS[i];
            if(obj===this){
                GAME_OBJECTS.splice(i,1);
                break;
            }
        }
    }

}
let last_timestamp;

const step=timestamp=>{
    for(let obj of GAME_OBJECTS){
        if(!obj.has_called_start){
            obj.has_called_start=true;
            obj.start();
        }
        else{
            obj.delta_time=timestamp-last_timestamp;
            obj.update();
        }
    }last_timestamp=timestamp;
    requestAnimationFrame(step);
}
requestAnimationFrame(step)